import { createSlice } from '@reduxjs/toolkit'

const initialState = {
    start:'北京',//出发地
    end:'上海',//目的地
}

export const counterSlice = createSlice({
  name: 'counter',
  initialState,
  reducers: {
    huan(state){//城市交换
        const temp=state.start
        state.start=state.end
        state.end=temp
    },
    setCity(state,{payload:{type,city}}){//保存点击的城市
      state[type]=city
    }
  },
})

// Action creators are generated for each case reducer function
export const { huan ,setCity} = counterSlice.actions

export default counterSlice.reducer